package com.example.demo03.web;

import com.example.demo03.pojo.User;
import com.example.demo03.service.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "registerServlet", value = "/registerServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1. 接收请求参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        // 2. 封装到实体类
        User u = new User();
        u.setUsername(username);
        u.setPassword(password);
        // 3. 将用户对象传递给service层
        UserServiceImpl userService = new UserServiceImpl();
        Boolean flag = userService.register(u);

        response.getWriter().print(flag);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
